<template>
  <div class="info-wrapper">
    <div class="info-nav-wrapper">
      <div class="info-nav">
        <div
          class="nav-item"
          v-for="(infoNav, index) in infoNavList"
          :key="infoNav"
          @click="navScroll(index)"
        >
          {{ infoNav }}
        </div>
        <div class="nav-scroll" :style="{}"></div>
      </div>
    </div>
    <div class="info-content-wrapper">
      <div class="content-wrapper">
        <div class="info-content">
          <div
            class="content-item"
            v-for="(item, index) in response"
            :key="item.id"
            @click="goDetail(item.id)"
          >
            <div class="item-img-wrapper">
              <img :src="getUrl(index)" alt="" />
            </div>
            <div class="item-content">
              <div class="content-title">{{ item.title }}</div>
              <div class="content-content">{{ item.content }}</div>
              <div class="content-label"></div>
              <div class="content-related">
                <div class="company">{{ item.company }}</div>
                <div class="date">{{ item.date }}</div>
                <div class="algo-wrapper" v-if="isAlgo()">
                  <div class="pay">
                    <img src="../assets/images/浏览@1x.png" alt="浏览" />
                    {{ item.browse }}
                  </div>
                  <div class="support">
                    <img src="../assets/images/点赞@1x.png" alt="点赞" />
                    {{ item.liked }}
                  </div>
                </div>
                <div class="demand-wrapper" v-else>
                  <div class="browse">
                    {{ item.browse }}人已浏览 /
                  </div>
                  &nbsp;
                  <div class="bid">
                    <span class="bid-count">{{item.bid}}</span>
                    人已投标
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="info-content">
          <div
            class="content-item"
            v-for="(item, index) in response"
            :key="item.id"
            @click="goDetail(item.id)"
          >
            <div class="item-img-wrapper">
              <img :src="getUrl(index)" alt="" />
            </div>
            <div class="item-content">
              <div class="content-title">{{ item.title }}</div>
              <div class="content-content">{{ item.content }}</div>
              <div class="content-label"></div>
              <div class="content-related">
                <div class="company">{{ item.company }}</div>
                <div class="date">{{ item.date }}</div>
                <div class="algo-wrapper" v-if="isAlgo()">
                  <div class="pay">
                    <img src="../assets/images/浏览@1x.png" alt="浏览" />
                    {{ item.browse }}
                  </div>
                  <div class="support">
                    <img src="../assets/images/点赞@1x.png" alt="点赞" />
                    {{ item.liked }}
                  </div>
                </div>
                <div class="demand-wrapper" v-else>
                  <div class="browse">
                    {{ item.browse }}人已浏览 /
                  </div>
                  &nbsp;
                  <div class="bid">
                    <span class="bid-count">{{item.bid}}</span>
                    人已投标
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="info-content">
          <div
            class="content-item"
            v-for="(item, index) in response"
            :key="item.id"
            @click="goDetail(item.id)"
          >
            <div class="item-img-wrapper">
              <img :src="getUrl(index)" alt="" />
            </div>
            <div class="item-content">
              <div class="content-title">{{ item.title }}</div>
              <div class="content-content">{{ item.content }}</div>
              <div class="content-label"></div>
              <div class="content-related">
                <div class="company">{{ item.company }}</div>
                <div class="date">{{ item.date }}</div>
                <div class="algo-wrapper" v-if="isAlgo()">
                  <div class="pay">
                    <img src="../assets/images/浏览@1x.png" alt="浏览" />
                    {{ item.browse }}
                  </div>
                  <div class="support">
                    <img src="../assets/images/点赞@1x.png" alt="点赞" />
                    {{ item.liked }}
                  </div>
                </div>
                <div class="demand-wrapper" v-else>
                  <div class="browse">
                    {{ item.browse }}人已浏览 /
                  </div>
                  &nbsp;
                  <div class="bid">
                    <span class="bid-count">{{item.bid}}</span>
                    人已投标
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "info-wrapper",
  data() {
    return {
      response: [],
    };
  },
  props: {
    allUrl: {
      type: String,
    },
    infoNavList: {
      type: Array,
    },
    detailUrl: {
      type: String,
    },
  },
  mounted() {
    axios({
      method: "GET",
      url: this.allUrl,
    }).then((response) => {
      //Promise  发送成功后的后续操作
      this.response = response.data.data;
    });
  },
  methods: {
    // 判断是否为算法广场页面
    isAlgo(){
      // 通过路径判断
      let algo = new RegExp("algorithm");
      if (algo.test(document.location)){
        return true;
      }else{
        return false;
      }
    },
    // 实现导航栏的滑动效果
    navScroll(index) {
      let navScroll = document.getElementsByClassName("nav-scroll")[0];
      let contentScroll = document.getElementsByClassName("content-wrapper")[0];
      navScroll.style.left = index * 104 + "px";
      contentScroll.style.left = -(index * contentScroll.offsetWidth) + "px";
    },
    // 获取每个item盒子的图片路径
    getUrl(index) {
      if (this.response[index].imgUrl == 0) {
        return require("../assets/images/noPic.jpg");
      } else {
        return "http://120.77.241.190:9999/"+this.response[index].imgUrl;
      }
    },
    // 跳转到模型或者需求详情页面
    goDetail(id) {
      axios({
        method: "GET",
        url: this.detailUrl + "?id=" + id,
      }).then((response) => {
        //Promise  发送成功后的后续操作
        let result = response.data.data;
      
        if (this.isAlgo()) {
          this.$router.push({
            name: "algoDetail",
            params: {
              algoid: result.id,
              result,
              history: "算法广场",
              // 便于后续点赞等需要用户信息的操作
              userData:this.$route.params.userData
            },
          });
        } else {
          this.$router.push({
            name: "demandDetail",
            params: {
              demandid: result.id,
              result,
              history: "需求广场",
              // 便于后续点赞等需要用户信息的操作
              userData:this.$route.params.userData
            },
          });
        }
      });
    },
  },
};
</script>
<style>
.info-wrapper {
  width: 67%;
  margin-top: 2%;
  margin-bottom: 2%;
  padding: 2%;
  background: #fff;
  color: #000;
  border-radius: 20px;
}
.info-nav-wrapper {
  width: 100%;
  color: #515a6e;
  border-bottom: 1px solid #dcdee2;
}
.info-banner {
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}
.info-nav {
  position: relative;
}
.info-nav .nav-item {
  font-size: 14px;
  display: inline-block;
  height: 100%;
  padding: 8px 16px;
  margin-right: 16px;
  box-sizing: border-box;
  cursor: pointer;
  color: #969bab;
}
.nav-scroll {
  width: 88px;
  height: 2px;
  box-sizing: border-box;
  background-color: #8c30f5;
  position: absolute;
  left: 0;
  bottom: -1px;
  z-index: 1;
  transition: left 0.3s ease-in-out;
  transform-origin: 0 0;
}

.content-wrapper {
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: row;
  left: 0px;
  transition: left 0.3s ease-in-out;
}
.info-content-wrapper {
  overflow: hidden;
}
.info-content {
  flex-shrink: 0;
  width: 100%;
}
.content-item {
  display: flex;
  padding: 3% 2% 3% 0;
  cursor: pointer;
  border-bottom: 1px solid #d9dbe1;
}
.item-img-wrapper > img {
  width: 230px;
  height: 180px;
}
.item-content {
  height: 150px;
  width: 70%;
  margin-left: 4%;
}
.content-title {
  font-size: 24px;
  color: #000;
  text-align: left;
}
.content-content {
  text-align: left;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #969bab;
  height: 60px;
  font-size: 14px;
}
.content-label {
  font-size: 12px;
  color: #969bab;
  display: flex;
  height: 65px;
}
.content-related {
  display: flex;
}
.content-related .company {
  font-size: 14px;
  color: #474a57;
  margin-right: 4%;
}

.content-related .date {
  font-size: 14px;
  margin-right: 4%;
  color: #969bab;
}
.algo-wrapper ,.demand-wrapper{
  display: flex;
}
.pay {
  margin-right: 15px;
  width: 65px;
}
.pay > img {
  width: 18px;
}
.support > img {
  width: 16px;
}
.bid-count{
  color: red;
}
</style>